package httprpc

import (
	"encoding/json"
	//"encoding/json"
	"fmt"
	"github.com/kirinlabs/HttpRequest"
	"time"
)

type ResponseData struct {
	Data int `json:"data"`
}

func LocalAdd(a, b int) int {
	req := HttpRequest.NewRequest()
	req.SetTimeout(10 * time.Second)
	resp, err := req.Get(fmt.Sprintf("http://127.0.0.1:8000/%s?a=%d&b=%d", "add", a, b))
	if err != nil {
		fmt.Println("err: ", err)
	}
	body, _ := resp.Body()
	var rd = ResponseData{}
	json.Unmarshal(body, &rd)
	return rd.Data
}

func Client() {
	res := LocalAdd(2, 59)
	fmt.Println(res)
	time.Sleep(5 * time.Second)
}
